package com.xps.and.yuntong.Ui;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.Overlay;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Polyline;
import com.baidu.mapapi.map.PolylineOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.RouteLine;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.BikingRouteResult;
import com.baidu.mapapi.search.route.DrivingRoutePlanOption;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.IndoorPlanNode;
import com.baidu.mapapi.search.route.IndoorRoutePlanOption;
import com.baidu.mapapi.search.route.IndoorRouteResult;
import com.baidu.mapapi.search.route.MassTransitRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;
import com.baidu.navisdk.adapter.BNCommonSettingParam;
import com.baidu.navisdk.adapter.BNOuterTTSPlayerCallback;
import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BNaviSettingManager;
import com.baidu.navisdk.adapter.BaiduNaviManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.xps.and.yuntong.Adapter.DingDanAdapter;
import com.xps.and.yuntong.App;
import com.xps.and.yuntong.Data.bean1.ArrivedDestination;
import com.xps.and.yuntong.Data.bean1.ArrivedParking;
import com.xps.and.yuntong.Data.bean1.Departure;
import com.xps.and.yuntong.Data.bean1.OrderDriver;
import com.xps.and.yuntong.Data.bean1.OrderSettlement;
import com.xps.and.yuntong.Data.model.MyTraceInfo;
import com.xps.and.yuntong.Data.net.UserNetWorks;
import com.xps.and.yuntong.R;
import com.xps.and.yuntong.Utils.AnimUtil;
import com.xps.and.yuntong.Utils.DrivingRouteOverlay;
import com.xps.and.yuntong.Utils.GlobalPositionInfo;
import com.xps.and.yuntong.Utils.OverlayManager;
import com.xps.and.yuntong.Utils.TimeUtil;
import com.xps.and.yuntong.Utils.TtsUtil;
import com.xps.and.yuntong.View.Custom.SliderControlView;
import com.xps.and.yuntong.baidu.BNDemoGuideActivity;
import com.xps.and.yuntong.baidu.BNEventHandler;
import com.xps.and.yuntong.base.BaseActivity;
import com.jude.utils.JUtils;

import java.io.File;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import jp.wasabeef.glide.transformations.CropCircleTransformation;
import rx.Subscriber;

/**
 * Created by administrator on 2017-12-15.
 */

public class DingdanKanActivity extends BaseActivity implements View.OnClickListener, BDLocationListener, BaiduMap.OnMapClickListener,
        OnGetRoutePlanResultListener {

    private MyReceiver receiver = null;
    private RelativeLayout rl_all, rl_middle1, rl_quanbu_s, rl_dengdai, rl_chufa, rl_daoda, rl_daohang, rl_top;
    private LinearLayout ll_boda_phone, ll_bottom1, ll_jiesuan_next, ll_top, rl_time_before;
    private TextView tv_middle, tv_touxiang, tv_touxiang1, tv_touxiang2, tv_touxiang3, tv_dizhi1, tv_dizhi2, tv2, tv_dengdai, tv_dengdai1, tv_yisong, tv_jiesuan;
    private ImageView iv_fanhui, iv_right, iv_lv_yuan, iv_lv_yuan1, iv_lv_yuan2, iv_lv_yuan3, iv_xiala, iv_bt_location;
    private ImageView iv_touxiang, iv_touxiang1, iv_touxiang2, iv_touxiang3;
    private RelativeLayout rl_touxiang, rl_touxiang1, rl_touxiang2, rl_touxiang3;

    private RelativeLayout rl_seekbar;
    private SeekBar id_seekbar_1;
    private SliderControlView sliderControlView;

    //接口内容
    private String bodaPhone = "";
    private String departure_time = "";
    private String order_state = "";
    private String order_state1 = "";
    private String order_state2 = "";
    private String order_state3 = "";
    private String order_id = "";
    private String driver_order_id = "";
    private long time = 0;
    private long time1 = 0;
    private long time2 = 0;
    private long time3 = 0;
    private Handler handler0 = new Handler();
    private Handler handler1 = new Handler();
    private Handler handler2 = new Handler();
    private Handler handler3 = new Handler();
    private Handler handler4 = new Handler();
    private int state_daoda = 0;
    private long currentTime;
    private int state_cilck = 0;
    private boolean flag_stateclick;
    private boolean flag_stateclick1;
    private boolean flag_stateclick2;
    private boolean flag_stateclick3;

    private Dialog bottomDialog;
    View contentView;
    private TextView tv_ok, tv_no;
    RouteLine route = null;
    DrivingRouteResult nowResultdrive = null;
    int span = 0;
    int locaTime = 0;
    MyTraceInfo myTraceInfo;
    /**
     * 存放所有marker
     */
    PlanNode[] str = {};
    List<PlanNode> listPlan;
    LatLng currentLatlng = null;
    private View view;
    private BaiduMap baiduMap;
    private MapView mapView;
    private LocationClient mLocationClient;
    private ArrayList<Overlay> overlays = new ArrayList<>();


    //测试用
    private TextView tv_dangqian_dizhi;
    float animFromY;
    ObjectAnimator animator, animator1;
    boolean animEnd;

    RoutePlanSearch mSearch = null;
    //导航
    public static List<Activity> activityList = new LinkedList<Activity>();
    private static final String APP_FOLDER_NAME = "BNSDKSimpleDemo";
    private String mSDCardPath = null;
    String startNodeStr = "西二旗地铁站";
    String endNodeStr = "百度科技园";
    public static final String ROUTE_PLAN_NODE = "routePlanNode";
    private final static String authBaseArr[] =
            {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION};
    private final static String authComArr[] = {Manifest.permission.READ_PHONE_STATE};
    private final static int authBaseRequestCode = 1;
    private final static int authComRequestCode = 2;

    private boolean hasInitSuccess = false;
    private boolean hasRequestComAuth = false;
    private Handler handler = new Handler();
    OverlayManager routeOverlay = null;

    private List<OrderDriver.ReturnBodyBean.StudentInfoBean> adapterListData = new ArrayList();
    private String bodaDianhua = "";
//    private DingdanKanActivity dingdanKanActivity;

    /* 持有私有静态实例，防止被引用，此处赋值为null，目的是实现延迟加载 */
    private static DingdanKanActivity instance = null;


    @Override
    protected int getLayout() {
        return R.layout.activity_chakan_dingdan;
    }

    @Override
    protected void setData() {

//        if (selectBean == null)
//            return;
//        if (TextUtils.isEmpty(selectBean.getEndLat()) || TextUtils.isEmpty(selectBean.getEndLng()))
//            return;
//        LatLng latLng = new LatLng(Double.valueOf(selectBean.getEndLat()), Double.valueOf(selectBean.getEndLng()));
//        myTraceInfo.updateEndMarker(latLng);

        //        App.getInstance().prepareYingYan();


    }

    @Override
    protected void init(Bundle inBundle) {
//        instance=DingdanKanActivity.getInstance();
        // 启动方式
        new DownloadFilesTask().execute(null, null, null);
        initView();
        mSearch = RoutePlanSearch.newInstance();
        mSearch.setOnGetRoutePlanResultListener(this);
        listPlan = new ArrayList<PlanNode>();
        listPlan.addAll(Arrays.asList(str));
        PlanNode stNode = PlanNode.withCityNameAndPlaceName("北京", startNodeStr);
        PlanNode enNode = PlanNode.withCityNameAndPlaceName("北京", endNodeStr);
        PlanNode enNode1 = PlanNode.withCityNameAndPlaceName("北京", "天安门");
        listPlan.add(enNode1);
        mSearch.drivingSearch((new DrivingRoutePlanOption())
                .from(stNode).to(enNode).passBy(listPlan));
    }
    /* 私有构造方法，防止被实例化 */
//    private DingdanKanActivity() {
//    }

    /* 1:懒汉式，静态工程方法，创建实例 */
    public static DingdanKanActivity getInstance() {
        if (instance == null) {
            instance = new DingdanKanActivity();
        }
        return instance;
    }

    private void initView() {
        mapView = (MapView) findViewById(R.id.mapView1);
        myTraceInfo = new MyTraceInfo(App.getInstance(), baiduMap);
        rl_all = (RelativeLayout) findViewById(R.id.rl_all);
        rl_middle1 = (RelativeLayout) findViewById(R.id.rl_middle1);
        rl_quanbu_s = (RelativeLayout) findViewById(R.id.rl_quanbu_s);
        rl_time_before = (LinearLayout) findViewById(R.id.rl_time_before);
        rl_dengdai = (RelativeLayout) findViewById(R.id.rl_dengdai);
        rl_chufa = (RelativeLayout) findViewById(R.id.rl_chufa);
        rl_daoda = (RelativeLayout) findViewById(R.id.rl_daoda);
        rl_daohang = (RelativeLayout) findViewById(R.id.rl_daohang);
        rl_touxiang = (RelativeLayout) findViewById(R.id.rl_touxiang);
        rl_touxiang1 = (RelativeLayout) findViewById(R.id.rl_touxiang1);
        rl_touxiang2 = (RelativeLayout) findViewById(R.id.rl_touxiang2);
        rl_touxiang3 = (RelativeLayout) findViewById(R.id.rl_touxiang3);
//        rl_seekbar = (RelativeLayout) findViewById(R.id.rl_seekbar);
//
//        id_seekbar_1 = (SeekBar) findViewById(R.id.id_seekbar_1);

        ll_boda_phone = (LinearLayout) findViewById(R.id.ll_boda_phone);
        ll_bottom1 = (LinearLayout) findViewById(R.id.ll_bottom1);
        ll_jiesuan_next = (LinearLayout) findViewById(R.id.ll_jiesuan_next);
        ll_top = (LinearLayout) findViewById(R.id.ll_top);

        tv_middle = (TextView) findViewById(R.id.tv_middle);
        tv_middle.setText(R.string.dingdan);
        tv_touxiang = (TextView) findViewById(R.id.tv_touxiang);
        tv_touxiang1 = (TextView) findViewById(R.id.tv_touxiang1);
        tv_touxiang2 = (TextView) findViewById(R.id.tv_touxiang2);
        tv_touxiang3 = (TextView) findViewById(R.id.tv_touxiang3);
        tv_dizhi1 = (TextView) findViewById(R.id.tv_dizhi1);
        tv_dizhi2 = (TextView) findViewById(R.id.tv_dizhi2);
        tv2 = (TextView) findViewById(R.id.tv2);
        tv_dengdai = (TextView) findViewById(R.id.tv_dengdai);
        tv_dengdai1 = (TextView) findViewById(R.id.tv_dengdai1);
        tv_jiesuan = (TextView) findViewById(R.id.tv_jiesuan);
        tv_yisong = (TextView) findViewById(R.id.tv_yisong);

        iv_fanhui = (ImageView) findViewById(R.id.iv_fanhui);
        iv_right = (ImageView) findViewById(R.id.iv_right);
        iv_right.setVisibility(View.GONE);
        iv_lv_yuan = (ImageView) findViewById(R.id.iv_lv_yuan);
        iv_lv_yuan1 = (ImageView) findViewById(R.id.iv_lv_yuan1);
        iv_lv_yuan2 = (ImageView) findViewById(R.id.iv_lv_yuan2);
        iv_lv_yuan3 = (ImageView) findViewById(R.id.iv_lv_yuan3);
        iv_xiala = (ImageView) findViewById(R.id.iv_xiala);
        iv_bt_location = (ImageView) findViewById(R.id.iv_bt_location);
        iv_touxiang = (ImageView) findViewById(R.id.iv_touxiang);
        iv_touxiang1 = (ImageView) findViewById(R.id.iv_touxiang1);
        iv_touxiang2 = (ImageView) findViewById(R.id.iv_touxiang2);
        iv_touxiang3 = (ImageView) findViewById(R.id.iv_touxiang3);

        sliderControlView = (SliderControlView) findViewById(R.id.sliderControlView);

        tv_dangqian_dizhi = (TextView) findViewById(R.id.tv_dangqian_dizhi);

        iv_fanhui.setOnClickListener(this);
        rl_dengdai.setOnClickListener(this);
        rl_chufa.setOnClickListener(this);
        rl_daoda.setOnClickListener(this);
        rl_daohang.setOnClickListener(this);
        rl_touxiang.setOnClickListener(this);
        rl_touxiang1.setOnClickListener(this);
        rl_touxiang2.setOnClickListener(this);
        rl_touxiang3.setOnClickListener(this);
        ll_boda_phone.setOnClickListener(this);
        ll_jiesuan_next.setOnClickListener(this);
        iv_xiala.setOnClickListener(this);
        iv_bt_location.setOnClickListener(this);
        rl_all.setOnClickListener(this);

        setUpMap();


        getOrderDriver();


        receiver = new MyReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.xps.and.yuntong.service.RemoteService");
        registerReceiver(receiver, filter);

        baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                JUtils.Toast(marker.getTitle());
                return true;
            }
        });
        sliderControlView.setSwitchListener(new SliderControlView.SwitchListener() {

            @Override
            public void onCompleted() {
                Log.e("111", "111111");
                if (state_cilck == 0) {
                    if (flag_stateclick == false) {
                        flag_stateclick = true;
                        arrivedParking(state_cilck);
                    }
                }
                if (state_cilck == 1) {
                    if (flag_stateclick1 == false) {
                        flag_stateclick1 = true;
                        arrivedParking(state_cilck);

                    }
                }
                if (state_cilck == 2) {
                    if (flag_stateclick2 == false) {
                        flag_stateclick2 = true;
                        arrivedParking(state_cilck);
                    }
                }
                if (state_cilck == 3) {
                    if (flag_stateclick3 == false) {
                        flag_stateclick3 = true;
                        arrivedParking(state_cilck);
                    }
                }
            }
        });
        rl_touxiang.setBackgroundResource(R.drawable.xian_kuang_lv);
        tv_touxiang.setTextColor(Color.parseColor("#2ebf12"));
    }


    void setUpMap() {
        mapView.showZoomControls(false);
        mapView.showScaleControl(false);
        baiduMap = mapView.getMap();

        baiduMap.getUiSettings().setCompassEnabled(false);
        baiduMap.getUiSettings().setZoomGesturesEnabled(true);
        baiduMap.getUiSettings().setOverlookingGesturesEnabled(false);
        baiduMap.setMyLocationEnabled(true);
        baiduMap.setViewPadding(35, 0, 20, 50);
        baiduMap.setMyLocationConfigeration(new MyLocationConfiguration(MyLocationConfiguration.LocationMode.FOLLOWING, true, null));

        mLocationClient = new LocationClient(App.getInstance());
        //activity里是否不能监听定位
        mLocationClient.registerLocationListener(this);
        periodLocation();
        huoquJingweidu();
    }


    //周期性定位的配置
    public void periodLocation() {
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setCoorType("bd09ll");
        int span = 1000 * 5;
        option.setScanSpan(span);
        option.setIsNeedAddress(true);
        option.setOpenGps(true);
        option.setLocationNotify(false);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        option.setIgnoreKillProcess(false);
        option.SetIgnoreCacheException(false);
        option.setEnableSimulateGps(false);
        mLocationClient.setLocOption(option);
        mLocationClient.start();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();


        onMapDestory();
//        animator.removeAllListeners();
//        BaiduNaviManager.getInstance().uninit();
    }


    public void onMapDestory() {
        mapView.onDestroy();
        baiduMap.setMyLocationEnabled(false);
        mLocationClient.stop();
        mLocationClient.unRegisterLocationListener(this);
//        geoCoder.destroy();
//        mRoutePlanSearch.destroy();
//        geoCoder = null;
        baiduMap.clear();
        baiduMap = null;
        mapView = null;
        myTraceInfo = null;
        mLocationClient.unRegisterLocationListener(this);
        mLocationClient = null;
        handler.removeCallbacksAndMessages(null);
        handler = null;
        handler0.removeCallbacksAndMessages(null);
        handler0 = null;
        handler1.removeCallbacksAndMessages(null);
        handler1 = null;
        handler2.removeCallbacksAndMessages(null);
        handler2 = null;
        handler3.removeCallbacksAndMessages(null);
        handler3 = null;
        handler4.removeCallbacksAndMessages(null);
        handler4 = null;
//        mRoutePlanSearch = null;
        Log.e("onMapDestory", "onMapDestory");
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.iv_fanhui:

//                Log.e("currentTime", TimeUtil.getCurTimeLong1() + "");
//                SharedPreferences sp = JUtils.getSharedPreference();
//                SharedPreferences.Editor spEd = sp.edit();
//                spEd.putLong("currentTime", TimeUtil.getCurTimeLong1());
//                spEd.putLong("currentTime1", TimeUtil.getCurTimeLong1());
//                spEd.putLong("currentTime2", TimeUtil.getCurTimeLong1());
//                spEd.putLong("currentTime3", TimeUtil.getCurTimeLong1());
//                currentTime = TimeUtil.getCurTimeLong1();
//                getTimeCha(departure_time);
//                spEd.commit();
                finish();
                break;
            case R.id.rl_dengdai:
                //只是为了测试而使用的,测试创建订单
//                Intent Establishintent = new Intent(DingdanKanActivity.this, ManuallyCreateOrderActivity.class);
//                startActivity(Establishintent);
                break;
            case R.id.iv_bt_location:
                recoveryCamera();
                break;

            case R.id.rl_chufa:
                rl_chufa.setEnabled(false);
                rl_chufa.setBackgroundColor(getResources().getColor(R.color.colorqianHui));
                departure(state_cilck);

                break;
            case R.id.rl_daoda:
                rl_daoda.setEnabled(false);
                rl_daoda.setBackgroundColor(getResources().getColor(R.color.colorqianHui));
                destination(state_cilck);
                break;
            case R.id.rl_daohang:
                Log.e("111", BaiduNaviManager.isNaviInited() + "");
                routeplanToNavi(BNRoutePlanNode.CoordinateType.WGS84);
                if (BaiduNaviManager.isNaviInited()) {
                    routeplanToNavi(BNRoutePlanNode.CoordinateType.WGS84);
                }
                break;

            case R.id.ll_boda_phone:
                if (bodaPhone == "") {
                    JUtils.Toast("请拨打正确电话");
                } else {
                    Intent phoneIntent = new Intent("android.intent.action.CALL",
                            Uri.parse("tel: " + bodaPhone));
                    startActivity(phoneIntent);
                }
                break;

            case R.id.ll_jiesuan_next:
                intDialog();
                break;

            case R.id.iv_xiala:

                animFromY = rl_all.getHeight() - ll_top.getHeight();
                rl_all.setTranslationY(animFromY);
                iv_xiala.setTranslationY(animFromY);

                animator = AnimUtil.getTranDownYAnim(animFromY, 0);
                animator1 = AnimUtil.getTranDownYAnim(animFromY, 0);
                animator.setTarget(rl_all);
                animator1.setTarget(iv_xiala);
                Log.e("animEnd", animEnd + "");
                if (animator.isRunning()) break;
                if (!animEnd) {
                    animEnd = true;
                    animator.start();
                    animator1.start();
                    iv_xiala.setImageResource(R.drawable.xia_la_shang);
                } else {
                    animEnd = false;
                    animator.reverse();
                    animator1.reverse();
                    iv_xiala.setImageResource(R.drawable.xia_la_xia);
                }


//                ArrowiMAGE animation = new ArrowiMAGE(iv_xiala, rl_all, 500);
//                rl_all.startAnimation(animation);


                break;

            case R.id.rl_touxiang:
                Log.e("order_state", order_state);
                state_cilck = 0;

                if (order_state.equals("4")) {
                    rl_touxiang.setEnabled(false);
                    handler0.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            rl_touxiang1.setEnabled(true);
                            rl_touxiang2.setEnabled(true);
                            rl_touxiang3.setEnabled(true);
                        }
                    }, 500);
                    departure_time = adapterListData.get(0).getDeparture_time();
                    getTimeCha(departure_time);
                } else {
                    rlXianshi();
                }

                stateWhere(order_state, adapterListData, 0);
                rl_touxiang.setBackgroundResource(R.drawable.xian_kuang_lv);
                tv_touxiang.setTextColor(Color.parseColor("#2ebf12"));
                rl_touxiang1.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang1.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang2.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang2.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang3.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang3.setTextColor(Color.parseColor("#8a8a8a"));


                tv_dizhi1.setText(adapterListData.get(0).getBegin_address());
                tv_dizhi2.setText(adapterListData.get(0).getEnd_address());
                tv2.setText(adapterListData.get(0).getDeparture_time().substring(11, 16));
                bodaPhone = adapterListData.get(0).getMobile_phone();
                order_id = adapterListData.get(0).getOrder_id();


                break;
            case R.id.rl_touxiang1:
                Log.e("order_state1", order_state1);
                state_cilck = 1;
                if (order_state1.equals("4")) {
                    rl_touxiang1.setEnabled(false);
                    handler0.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            rl_touxiang.setEnabled(true);
                            rl_touxiang2.setEnabled(true);
                            rl_touxiang3.setEnabled(true);
                        }
                    }, 500);
                    departure_time = adapterListData.get(1).getDeparture_time();
                    getTimeCha(departure_time);
                } else {
                    rlXianshi();
                }

                stateWhere(order_state1, adapterListData, 1);
                rl_touxiang1.setBackgroundResource(R.drawable.xian_kuang_lv);
                tv_touxiang1.setTextColor(Color.parseColor("#2ebf12"));
                rl_touxiang.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang2.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang2.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang3.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang3.setTextColor(Color.parseColor("#8a8a8a"));

                tv_dizhi1.setText(adapterListData.get(1).getBegin_address());
                tv_dizhi2.setText(adapterListData.get(1).getEnd_address());
                tv2.setText(adapterListData.get(1).getDeparture_time().substring(11, 16));
                bodaPhone = adapterListData.get(1).getMobile_phone();
                order_id = adapterListData.get(1).getOrder_id();
                break;
            case R.id.rl_touxiang2:
                Log.e("order_state2", order_state2);
                state_cilck = 2;

                if (order_state2.equals("4")) {
                    departure_time = adapterListData.get(2).getDeparture_time();
                    getTimeCha(departure_time);
                    rl_touxiang2.setEnabled(false);
                    handler0.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            rl_touxiang.setEnabled(true);
                            rl_touxiang1.setEnabled(true);
                            rl_touxiang3.setEnabled(true);
                        }
                    }, 500);
                } else {
                    rlXianshi();
                }

                stateWhere(order_state2, adapterListData, 2);

                rl_touxiang2.setBackgroundResource(R.drawable.xian_kuang_lv);
                tv_touxiang2.setTextColor(Color.parseColor("#2ebf12"));
                rl_touxiang1.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang1.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang3.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang3.setTextColor(Color.parseColor("#8a8a8a"));

                tv_dizhi1.setText(adapterListData.get(2).getBegin_address());
                tv_dizhi2.setText(adapterListData.get(2).getEnd_address());
                tv2.setText(adapterListData.get(2).getDeparture_time().substring(11, 16));
                bodaPhone = adapterListData.get(2).getMobile_phone();
                order_id = adapterListData.get(2).getOrder_id();

                break;
            case R.id.rl_touxiang3:
                Log.e("order_state3", order_state3);
                state_cilck = 3;
                if (order_state3.equals("4")) {
                    departure_time = adapterListData.get(3).getDeparture_time();
                    getTimeCha(departure_time);
                    rl_touxiang3.setEnabled(false);
                    handler0.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            rl_touxiang.setEnabled(true);
                            rl_touxiang1.setEnabled(true);
                            rl_touxiang2.setEnabled(true);
                        }
                    }, 500);
                } else {
                    rlXianshi();
                }

                stateWhere(order_state3, adapterListData, 3);
                rl_touxiang3.setBackgroundResource(R.drawable.xian_kuang_lv);
                tv_touxiang3.setTextColor(Color.parseColor("#2ebf12"));
                rl_touxiang1.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang1.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang2.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang2.setTextColor(Color.parseColor("#8a8a8a"));
                rl_touxiang.setBackgroundResource(R.drawable.xian_kuang);
                tv_touxiang.setTextColor(Color.parseColor("#8a8a8a"));
                tv_dizhi1.setText(adapterListData.get(3).getBegin_address());
                tv_dizhi2.setText(adapterListData.get(3).getEnd_address());
                tv2.setText(adapterListData.get(3).getDeparture_time().substring(11, 16));
                bodaPhone = adapterListData.get(3).getMobile_phone();
                order_id = adapterListData.get(3).getOrder_id();
                break;


        }
    }


    //以下是地图部分

    /**
     * 添加一个marker 在map上
     */
    public void addMarkerMl(LatLng lat, String str) {
        LatLng point = lat;
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.qcml_img);

        OverlayOptions option = new MarkerOptions()
                .position(point)
                .title(str)
                .icon(bitmap);
        overlays.add(baiduMap.addOverlay(option));
    }

    /**
     * 清除所有marker
     */
    public void removeMarkers() {
        Iterator<Overlay> overlayIterator = overlays.iterator();
        while (overlayIterator.hasNext()) {
            overlayIterator.next().remove();
        }
    }

    @Override
    public void onReceiveLocation(BDLocation location) {
        LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
        currentLatlng = latLng;
        if (span == 0 && locaTime == 0) {
            currentLatlng = latLng;
            recoveryCamera();
            locaTime++;
        }
    }

    /**
     * 移动镜头到指定经纬度
     *
     * @param latLng 坐标点
     */
    public void moveCameraTo(LatLng latLng) {
        if (baiduMap == null) return;
        MapStatus mMapStatus = new MapStatus.Builder().target(latLng
        ).zoom(17).build();
        MapStatusUpdate u = MapStatusUpdateFactory.newMapStatus(mMapStatus);
        baiduMap.animateMapStatus(u);
    }

    public void recoveryCamera() {
        if (currentLatlng != null)
            moveCameraTo(currentLatlng);
    }


    //dialog的出现
    private void intDialog() {

        bottomDialog = new Dialog(this, R.style.BottomDialog);
        contentView = LayoutInflater.from(this).inflate(R.layout.dialog_dingdan, null);
        bottomDialog.setContentView(contentView);
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) contentView.getLayoutParams();

        contentView.setLayoutParams(params);
        bottomDialog.setCanceledOnTouchOutside(true);
        bottomDialog.getWindow().setGravity(Gravity.CENTER);
        bottomDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
        tv_ok = (TextView) contentView.findViewById(R.id.ok);
        tv_no = (TextView) contentView.findViewById(R.id.quxiao);
        bottomDialog.show();


        Window dialogWindow = bottomDialog.getWindow();
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高度
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
//        p.height = (int) (d.getHeight() * 0.3); // 高度设置为屏幕的0.6，根据实际情况调整
        p.width = (int) (d.getWidth() * 0.65); // 宽度设置为屏幕的0.65，根据实际情况调整
        dialogWindow.setAttributes(p);


        tv_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                tv_ok.setEnabled(false);
                orderSettlement();


            }
        });
        tv_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomDialog.dismiss();
            }
        });


    }


    /**
     * 添加一个marker 在map上
     */
    public void addMarker(LatLng lat, String str, BaiduMap baiduMap) {
        Marker marker;
        LatLng point = lat;
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.icon_markx);

        OverlayOptions option = new MarkerOptions()
                .position(point)
                .title(str)
                .icon(bitmap);
        overlays.add(baiduMap.addOverlay(option));
    }


    //获取经纬度
    private void huoquJingweidu() {
        DingdanKanActivity.getInstance().removeMarkers();
        GlobalPositionInfo globalPositionInfo = App.getInstance().getGloPosinfo();
        if (globalPositionInfo == null) return;
        BDLocation bdloca = globalPositionInfo.bdLocation;
        if (bdloca == null) return;
//        if(baiduMap==null){return;}
        Log.e("111", bdloca.getLatitude() + "====" + bdloca.getLongitude());
        tv_dangqian_dizhi.setText(bdloca.getAddress().address);
        markerXian(bdloca);
    }


//    void placeMarker(MapBean mapBean) {
//        for (int i = 0; i < mapBean.getReturn_body().size(); i++) {
//            MapBean.ReturnBodyBean reb = mapBean.getReturn_body().get(i);
//            MapBean.ReturnBodyBean.LatestLocationBean latestLocationBean = reb.getLatest_location();
//            LatLng location_point = new LatLng(latestLocationBean.getLatitude(), latestLocationBean.getLongitude());
//            dingdanKanActivity.addMarker(location_point, reb.getEntity_desc());
//        }
//    }


    private void markerXian(BDLocation bdloca) {
        LatLng location_point = new LatLng(bdloca.getLatitude(), bdloca.getLongitude());
        LatLng location_point1 = new LatLng(39.102798, 117.246123);
        LatLng location_point2 = new LatLng(39.102642, 117.245128);
        LatLng location_point3 = new LatLng(39.103258, 117.246116);
        LatLng location_point4 = new LatLng(38.103258, 117.246116);
//        dingdanKanActivity.addMarker(location_point,bdloca.getAddress().address,baiduMap);
        DingdanKanActivity.getInstance().addMarker(location_point1, bdloca.getAddress().address, baiduMap);
        DingdanKanActivity.getInstance().addMarker(location_point2, bdloca.getAddress().address, baiduMap);
        DingdanKanActivity.getInstance().addMarker(location_point3, bdloca.getAddress().address, baiduMap);
        DingdanKanActivity.getInstance().addMarker(location_point4, bdloca.getAddress().address, baiduMap);
        //构建折线点坐标
//        LatLng p1 = new LatLng(39.97923, 116.357428);
//        LatLng p2 = new LatLng(39.94923, 116.397428);
//        LatLng p3 = new LatLng(39.97923, 116.437428);
        List<LatLng> points = new ArrayList<LatLng>();
        points.add(location_point1);
        points.add(location_point2);
        points.add(location_point3);
        points.add(location_point4);
//        points.add(location_point);

        //绘制折线
        OverlayOptions ooPolyline = new PolylineOptions().width(10)
                .color(0xAAFF0000).points(points);
        Polyline mPolyline = (Polyline) baiduMap.addOverlay(ooPolyline);
    }

    private boolean initDirs() {
        mSDCardPath = getSdcardDir();
        if (mSDCardPath == null) {
            return false;
        }
        File f = new File(mSDCardPath, APP_FOLDER_NAME);
        if (!f.exists()) {
            try {
                f.mkdir();
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }

    String authinfo = null;

    /**
     * 内部TTS播报状态回传handler
     */
    private Handler ttsHandler = new Handler() {
        public void handleMessage(Message msg) {
            int type = msg.what;
            switch (type) {
                case BaiduNaviManager.TTSPlayMsgType.PLAY_START_MSG: {
                    // showToastMsg("Handler : TTS play start");
                    break;
                }
                case BaiduNaviManager.TTSPlayMsgType.PLAY_END_MSG: {
                    // showToastMsg("Handler : TTS play end");
                    break;
                }
                default:
                    break;
            }
        }
    };

    /**
     * 内部TTS播报状态回调接口
     */
    private BaiduNaviManager.TTSPlayStateListener ttsPlayStateListener = new BaiduNaviManager.TTSPlayStateListener() {

        @Override
        public void playEnd() {
            // showToastMsg("TTSPlayStateListener : TTS play end");
        }

        @Override
        public void playStart() {
//            ttsPlayStateListener.playStart();
            // showToastMsg("TTSPlayStateListener : TTS play start");
        }
    };

    public void showToastMsg(final String msg) {
        DingdanKanActivity.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(DingdanKanActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private boolean hasBasePhoneAuth() {
        // TODO Auto-generated method stub

        PackageManager pm = this.getPackageManager();
        for (String auth : authBaseArr) {
            if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    private boolean hasCompletePhoneAuth() {
        // TODO Auto-generated method stub

        PackageManager pm = this.getPackageManager();
        for (String auth : authComArr) {
            if (pm.checkPermission(auth, this.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    private void initNavi() {

        BNOuterTTSPlayerCallback ttsCallback = null;

        // 申请权限
        if (android.os.Build.VERSION.SDK_INT >= 23) {

            if (!hasBasePhoneAuth()) {

                this.requestPermissions(authBaseArr, authBaseRequestCode);
                return;

            }
        }

        BaiduNaviManager.getInstance().init(this, mSDCardPath, APP_FOLDER_NAME, new BaiduNaviManager.NaviInitListener() {
            @Override
            public void onAuthResult(int status, String msg) {
                if (0 == status) {
                    authinfo = "key校验成功!";
                } else {
                    authinfo = "key校验失败, " + msg;
                }
                DingdanKanActivity.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Toast.makeText(DingdanKanActivity.this, authinfo, Toast.LENGTH_LONG).show();
                    }
                });
            }

            public void initSuccess() {
                Toast.makeText(DingdanKanActivity.this, "百度导航引擎初始化成功", Toast.LENGTH_SHORT).show();
                dissmisDialog();
                hasInitSuccess = true;
                initSetting();
            }

            public void initStart() {
                showDialogNoCancel();
                Toast.makeText(DingdanKanActivity.this, "百度导航引擎初始化开始", Toast.LENGTH_SHORT).show();
            }

            public void initFailed() {
                Toast.makeText(DingdanKanActivity.this, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show();
            }

        }, null, ttsHandler, ttsPlayStateListener);

    }

    private String getSdcardDir() {
        if (Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED)) {
            return Environment.getExternalStorageDirectory().toString();
        }
        return null;
    }

    private BNRoutePlanNode.CoordinateType mCoordinateType = null;

    private void routeplanToNavi(BNRoutePlanNode.CoordinateType coType) {
        mCoordinateType = coType;
        if (!hasInitSuccess) {
            Toast.makeText(DingdanKanActivity.this, "还未初始化!", Toast.LENGTH_SHORT).show();
        }
        // 权限申请
        if (android.os.Build.VERSION.SDK_INT >= 23) {
            // 保证导航功能完备
            if (!hasCompletePhoneAuth()) {
                if (!hasRequestComAuth) {
                    hasRequestComAuth = true;
                    this.requestPermissions(authComArr, authComRequestCode);
                    return;
                } else {
                    Toast.makeText(DingdanKanActivity.this, "没有完备的权限!", Toast.LENGTH_SHORT).show();
                }
            }

        }
        BNRoutePlanNode sNode = null;
        BNRoutePlanNode eNode = null;
        switch (coType) {
            case GCJ02: {
                sNode = new BNRoutePlanNode(117.246123, 39.102798, "天津", null, coType);
                eNode = new BNRoutePlanNode(116.39750, 39.90882, "天津卫", null, coType);
                break;
            }
            case WGS84: {
                sNode = new BNRoutePlanNode(117.246116, 39.103258, "南北大街", null, coType);
                eNode = new BNRoutePlanNode(116.397491, 39.908749, "北京天安门", null, coType);
                break;
            }
            case BD09_MC: {
                sNode = new BNRoutePlanNode(12947471, 4846474, "百度大厦", null, coType);
                eNode = new BNRoutePlanNode(12958160, 4825947, "北京天安门", null, coType);
                break;
            }
            case BD09LL: {
                sNode = new BNRoutePlanNode(116.30784537597782, 40.057009624099436, "百度大厦", null, coType);
                eNode = new BNRoutePlanNode(116.40386525193937, 39.915160800132085, "北京天安门", null, coType);
                break;
            }
            default:
                ;
        }
        if (sNode != null && eNode != null) {
            List<BNRoutePlanNode> list = new ArrayList<BNRoutePlanNode>();
            list.add(sNode);
            list.add(eNode);

            // 开发者可以使用旧的算路接口，也可以使用新的算路接口,可以接收诱导信息等
            // BaiduNaviManager.getInstance().launchNavigator(this, list, 1, true, new DemoRoutePlanListener(sNode));
            BaiduNaviManager.getInstance().launchNavigator(this, list, 1, true, new DemoRoutePlanListener(sNode),
                    eventListerner);
        }
    }

    BaiduNaviManager.NavEventListener eventListerner = new BaiduNaviManager.NavEventListener() {

        @Override
        public void onCommonEventCall(int what, int arg1, int arg2, Bundle bundle) {
            BNEventHandler.getInstance().handleNaviEvent(what, arg1, arg2, bundle);
        }
    };

    @Override
    public void onMapClick(LatLng latLng) {

    }

    @Override
    public boolean onMapPoiClick(MapPoi mapPoi) {
        return false;
    }

    @Override
    public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {

    }

    @Override
    public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {

    }

    @Override
    public void onGetMassTransitRouteResult(MassTransitRouteResult massTransitRouteResult) {

    }

    @Override
    public void onGetDrivingRouteResult(DrivingRouteResult result) {
        {
            if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
                Toast.makeText(DingdanKanActivity.this, "抱歉，未找到结果", Toast.LENGTH_SHORT).show();
            }
            if (result.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
                // 起终点或途经点地址有岐义，通过以下接口获取建议查询信息
                // result.getSuggestAddrInfo()
                return;
            }
            if (result.error == SearchResult.ERRORNO.NO_ERROR) {
                route = result.getRouteLines().get(0);
                DrivingRouteOverlay overlay = new MyDrivingRouteOverlay(baiduMap);
                routeOverlay = overlay;
                baiduMap.setOnMarkerClickListener(overlay);
                overlay.setData(result.getRouteLines().get(0));
                overlay.addToMap();
                overlay.zoomToSpan();
            } else {
                Log.d("route result", "结果数<0");
                return;
            }

        }
    }


    @Override
    public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {

    }

    @Override
    public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {

    }


    public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener {

        private BNRoutePlanNode mBNRoutePlanNode = null;

        public DemoRoutePlanListener(BNRoutePlanNode node) {
            mBNRoutePlanNode = node;
        }

        @Override
        public void onJumpToNavigator() {
            /*
             * 设置途径点以及resetEndNode会回调该接口
             */

            for (Activity ac : activityList) {

                if (ac.getClass().getName().endsWith("BNDemoGuideActivity")) {

                    return;
                }
            }
            Intent intent = new Intent(DingdanKanActivity.this, BNDemoGuideActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode);
            intent.putExtras(bundle);
            startActivity(intent);

        }

        @Override
        public void onRoutePlanFailed() {
            // TODO Auto-generated method stub
            Toast.makeText(DingdanKanActivity.this, "算路失败", Toast.LENGTH_SHORT).show();
        }
    }

    private void initSetting() {
        // BNaviSettingManager.setDayNightMode(BNaviSettingManager.DayNightMode.DAY_NIGHT_MODE_DAY);
        BNaviSettingManager
                .setShowTotalRoadConditionBar(BNaviSettingManager.PreViewRoadCondition.ROAD_CONDITION_BAR_SHOW_ON);
        BNaviSettingManager.setVoiceMode(BNaviSettingManager.VoiceMode.Veteran);
        // BNaviSettingManager.setPowerSaveMode(BNaviSettingManager.PowerSaveMode.DISABLE_MODE);
        BNaviSettingManager.setRealRoadCondition(BNaviSettingManager.RealRoadCondition.NAVI_ITS_ON);
        BNaviSettingManager.setIsAutoQuitWhenArrived(true);
        Bundle bundle = new Bundle();
        // 必须设置APPID，否则会静音
        bundle.putString(BNCommonSettingParam.TTS_APP_ID, "10720617");
        BNaviSettingManager.setNaviSdkParam(bundle);
    }

    private BNOuterTTSPlayerCallback mTTSCallback = new BNOuterTTSPlayerCallback() {

        @Override
        public void stopTTS() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "stopTTS");
        }

        @Override
        public void resumeTTS() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "resumeTTS");
        }

        @Override
        public void releaseTTSPlayer() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "releaseTTSPlayer");
        }

        @Override
        public int playTTSText(String speech, int bPreempt) {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "playTTSText" + "_" + speech + "_" + bPreempt);

            return 1;
        }

        @Override
        public void phoneHangUp() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "phoneHangUp");
        }

        @Override
        public void phoneCalling() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "phoneCalling");
        }

        @Override
        public void pauseTTS() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "pauseTTS");
        }

        @Override
        public void initTTSPlayer() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "initTTSPlayer");
        }

        @Override
        public int getTTSState() {
            // TODO Auto-generated method stub
            Log.e("test_TTS", "getTTSState");
            return 1;
        }
    };
    boolean useDefaultIcon = false;

    private class MyDrivingRouteOverlay extends DrivingRouteOverlay {

        public MyDrivingRouteOverlay(BaiduMap baiduMap) {
            super(baiduMap);
        }

        @Override
        public BitmapDescriptor getStartMarker() {
            if (useDefaultIcon) {
                return BitmapDescriptorFactory.fromResource(R.drawable.icon_st);
            }
            return null;
        }

        @Override
        public BitmapDescriptor getTerminalMarker() {
            if (useDefaultIcon) {
                return BitmapDescriptorFactory.fromResource(R.drawable.icon_en);
            }
            return null;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        // TODO Auto-generated method stub
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == authBaseRequestCode) {
            for (int ret : grantResults) {
                if (ret == 0) {
                    continue;
                } else {
                    Toast.makeText(DingdanKanActivity.this, "缺少导航基本的权限!", Toast.LENGTH_SHORT).show();
                    return;
                }
            }
            initNavi();
        } else if (requestCode == authComRequestCode) {
            for (int ret : grantResults) {
                if (ret == 0) {
                    continue;
                }
            }
            routeplanToNavi(mCoordinateType);
        }

    }


    //避免ANR做的措施
    private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
        // Do the long-running work in here
        // 执行在子线程
        protected Long doInBackground(URL... urls) {
            long totalSize = 0;
            Log.e("111", "走了吗" + initDirs());
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.e("111", "走了吗1" + initDirs());
                    //百度导航引擎初始化
                    if (initDirs()) {

//                        initNavi();

                    }
                }
            }, 10000);

//            //百度导航引擎初始化
//            if (initDirs()) {
//
//                initNavi();
//
//            }
            return totalSize;
        }

        // This is called each time you call publishProgress()
        // 执行在主线程
        protected void onProgressUpdate(Integer... progress) {

        }

        // This is called when doInBackground() is finished
        // 执行在主线程
        protected void onPostExecute(Long result) {
        }
    }

    private void getOrderDriver() {

        UserNetWorks.getOrederDiver("aaa", new Subscriber<OrderDriver>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(OrderDriver orderDriver) {
                Log.e("111", orderDriver.getReturn_msg() + "");
                if (orderDriver.getReturn_body() == null) {

                } else {

                    driver_order_id = orderDriver.getReturn_body().getOrderInfo().getOrder_id();
                    Log.e("111", orderDriver.getReturn_body().getOrderInfo() + "");
                    List<OrderDriver.ReturnBodyBean.StudentInfoBean> list = orderDriver.getReturn_body().getStudentInfo();
                    OrderDriver.ReturnBodyBean.OrderInfoBean orderInfoBean = orderDriver.getReturn_body().getOrderInfo();
                    Log.e("111", list.toString() + "");

                    adapterListData = list;
                    if (adapterListData.size() > 0) {
                        tv_dizhi1.setText(adapterListData.get(0).getBegin_address());
                        tv_dizhi2.setText(adapterListData.get(0).getEnd_address());
                        bodaPhone = adapterListData.get(0).getMobile_phone();
                        departure_time = adapterListData.get(0).getDeparture_time();
                        order_id = adapterListData.get(0).getOrder_id();
                        tv2.setText(departure_time.substring(11, 16) + "");
                    }
                    if (list != null && list.size() <= 0) {
                        return;
                    } else if (list.size() == 1) {
                        order_state = list.get(0).getOrder_state();
                        String str = list.get(0).getHead_img();
                        Glide.with(DingdanKanActivity.this).load(str)
                                .placeholder(R.mipmap.logo)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang);
                        tv_touxiang.setText(list.get(0).getName());
                        rl_touxiang1.setVisibility(View.GONE);
                        rl_touxiang2.setVisibility(View.GONE);
                        rl_touxiang3.setVisibility(View.GONE);
                        if (!order_state.equals("6")) {
                            stateWhere(order_state, list, 0);
                            departure_time = adapterListData.get(0).getDeparture_time();
                            if (order_state.equals("4")) {
                                getTimeCha(departure_time);
                                rl_touxiang.setEnabled(false);
                            }
                        } else {
                            iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                            stateWhere(order_state, list, 0);
//                            stateall();
                        }

                    } else if (list.size() == 2) {
                        order_state = list.get(0).getOrder_state();
                        order_state1 = list.get(1).getOrder_state();
                        rl_touxiang2.setVisibility(View.GONE);
                        rl_touxiang3.setVisibility(View.GONE);
                        String str = list.get(0).getHead_img();
                        String str1 = list.get(1).getHead_img();
                        Glide.with(DingdanKanActivity.this).load(str)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang);
                        Glide.with(DingdanKanActivity.this).load(str1)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang1);
                        tv_touxiang.setText(list.get(0).getName());
                        tv_touxiang1.setText(list.get(1).getName());
                        if (order_state.equals("6") && order_state1.equals("6")) {
                            stateall();
                        } else {

                            if (!order_state1.equals("6")) {
                                stateWhere(order_state1, list, 1);
                            } else {
                                iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state1, list, 1);
                            }
                            if (!order_state.equals("6")) {
                                stateWhere(order_state, list, 0);
                                departure_time = adapterListData.get(0).getDeparture_time();
                                if (order_state.equals("4")) {
                                    getTimeCha(departure_time);
                                    rl_touxiang.setEnabled(false);
                                }
                            } else {
                                iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state, list, 0);
                            }

                        }
                    } else if (list.size() == 3) {
                        order_state = list.get(0).getOrder_state();
                        order_state1 = list.get(1).getOrder_state();
                        order_state2 = list.get(2).getOrder_state();
                        String str = list.get(0).getHead_img();
                        String str1 = list.get(1).getHead_img();
                        String str2 = list.get(2).getHead_img();
                        Glide.with(DingdanKanActivity.this).load(str)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang);
                        Glide.with(DingdanKanActivity.this).load(str1)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang1);
                        Glide.with(DingdanKanActivity.this).load(str2)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang2);
                        tv_touxiang.setText(list.get(0).getName());
                        tv_touxiang1.setText(list.get(1).getName());
                        tv_touxiang2.setText(list.get(2).getName());
                        rl_touxiang3.setVisibility(View.GONE);
                        if (order_state.equals("6") && order_state1.equals("6") && order_state2.equals("6")) {
                            stateall();

                        } else {


                            if (!order_state2.equals("6")) {
                                stateWhere(order_state2, list, 2);
                            } else {
                                iv_lv_yuan2.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state2, list, 2);
                            }
                            if (!order_state1.equals("6")) {
                                stateWhere(order_state1, list, 1);

                            } else {
                                iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state1, list, 1);
                            }
                            if (!order_state.equals("6")) {
                                stateWhere(order_state, list, 0);
                                departure_time = adapterListData.get(0).getDeparture_time();
                                if (order_state.equals("4")) {
                                    getTimeCha(departure_time);
                                    rl_touxiang.setEnabled(false);
                                }
                            } else {
                                iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state, list, 0);

                            }


                        }
                    } else if (list.size() == 4) {
                        order_state = list.get(0).getOrder_state();
                        order_state1 = list.get(1).getOrder_state();
                        order_state2 = list.get(2).getOrder_state();
                        order_state3 = list.get(3).getOrder_state();
                        //设置头像
                        String str = list.get(0).getHead_img();
                        String str1 = list.get(1).getHead_img();
                        String str2 = list.get(2).getHead_img();
                        String str3 = list.get(3).getHead_img();
                        Glide.with(DingdanKanActivity.this).load(str)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang);
                        Glide.with(DingdanKanActivity.this).load(str1)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang1);
                        Glide.with(DingdanKanActivity.this).load(str2)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang2);
                        Glide.with(DingdanKanActivity.this).load(str3)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)//禁用磁盘缓存
                                .skipMemoryCache(true)
                                .bitmapTransform(new CropCircleTransformation(DingdanKanActivity.this))
                                .into(iv_touxiang3);
                        tv_touxiang.setText(list.get(0).getName());
                        tv_touxiang1.setText(list.get(1).getName());
                        tv_touxiang2.setText(list.get(2).getName());
                        tv_touxiang3.setText(list.get(3).getName());

                        Log.e("111", order_state + "===" + order_state1 + "===" + order_state1 + "===" + order_state1 + "===");
                        if (order_state.equals("6") && order_state1.equals("6") && order_state2.equals("6") && order_state3.equals("6")) {
                            stateall();

                        } else {


                            if (!order_state3.equals("6")) {
                                stateWhere(order_state3, list, 3);

                            } else {
                                iv_lv_yuan3.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state3, list, 3);
                            }
                            if (!order_state2.equals("6")) {
                                stateWhere(order_state2, list, 2);

                            } else {
                                iv_lv_yuan2.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state2, list, 2);
                            }
                            if (!order_state1.equals("6")) {
                                stateWhere(order_state1, list, 1);

                            } else {
                                iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state1, list, 1);
                            }
                            if (!order_state.equals("6")) {
                                stateWhere(order_state, list, 0);
                                departure_time = adapterListData.get(0).getDeparture_time();
                                if (order_state.equals("4")) {
                                    getTimeCha(departure_time);
                                    rl_touxiang.setEnabled(false);
                                }

                            } else {
                                iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                                stateWhere(order_state, list, 0);

                            }

                        }
                    }


//                    dingdan_hao=orderDriver.getReturn_body().getOrderInfo().getOrder_sn();

                }

            }
        });


    }

    private void getTimeCha(String departure_time) {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date d2 = new Date(System.currentTimeMillis());//你也可以获取当前时间

//            Date d1 = df.parse(departure_time); //约定时间
            Date d1 = df.parse("2018-01-30 15:57:22"); //约定时间
//                    Date d2 = df.parse("2018-01-23 05:57:22");
            long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别
            long days = diff / (1000 * 60 * 60 * 24);
            long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
            long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
            long s = (diff / 1000 - days * 24 * 60 * 60 - hours * 60 * 60 - minutes * 60);

            Log.e("111", "" + days + "天" + hours + "小时" + minutes + "分");
            Log.e("111", String.valueOf(d1.getTime() + String.valueOf(d2.getTime())));
            long minute = hours * 60 + minutes;
            if (s >= 0 && days == 0) {
                time = hours * 60 * 60 + minutes * 60 + s + 60;
                time1 = hours * 60 * 60 + minutes * 60 + s + 60;
                time2 = hours * 60 * 60 + minutes * 60 + s + 60;
                time3 = hours * 60 * 60 + minutes * 60 + s + 60;

            } else if (s <= 0 && days == 0) {
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime", 1l) <= 60) {
                    time = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime1", 1l) <= 60) {
                    time1 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime1", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime2", 1l) <= 60) {
                    time2 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime2", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime3", 1l) <= 60) {
                    time3 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime3", 1l);
                }
            } else if (s <= 0 && days != 0) {
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime", 1l) <= 60) {
                    time = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime1", 1l) <= 60) {
                    time1 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime1", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime2", 1l) <= 60) {
                    time2 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime2", 1l);
                }
                if (TimeUtil.getCurTimeLong1() - JUtils.getSharedPreference().getLong("currentTime3", 1l) <= 60) {
                    time3 = 60 - TimeUtil.getCurTimeLong1() + JUtils.getSharedPreference().getLong("currentTime3", 1l);
                }
            }
            Log.e("111", time + "===" + time1);
            if (state_cilck == 0) {

                time1 = 1;
                time2 = 1;
                time3 = 1;
                if (time > 0) {
                    handler1.postDelayed(runnable, 1000);
                }
            } else if (state_cilck == 1) {
                time = 1;
                time2 = 1;
                time3 = 1;
                if (time1 > 0) {
                    handler2.postDelayed(runnable1, 1000);
                }
            } else if (state_cilck == 2) {
                time = 1;
                time1 = 1;
                time3 = 1;
                if (time2 > 0) {
                    handler3.postDelayed(runnable2, 1000);

                }
            } else if (state_cilck == 3) {
                time = 1;
                time2 = 1;
                time1 = 1;
                if (time3 > 0) {
                    handler4.postDelayed(runnable3, 1000);
                }
            }


        } catch (Exception e) {
        }


    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            time--;
            String formatLongToTimeStr = formatLongToTimeStr(time);
            String[] split = formatLongToTimeStr.split("：");
            for (int i = 0; i < split.length; i++) {
                if (i == 0) {
                    tv_dengdai.setText(split[0] + ":");
                }
                if (i == 1) {
                    tv_dengdai1.setText(split[1]);
                }

            }
            if (time > 0) {
                handler1.postDelayed(this, 1000);
            }
        }
    };

    Runnable runnable1 = new Runnable() {
        @Override
        public void run() {
            time1--;
            String formatLongToTimeStr = formatLongToTimeStr(time1);
            String[] split = formatLongToTimeStr.split("：");
            for (int i = 0; i < split.length; i++) {
                if (i == 0) {
                    tv_dengdai.setText(split[0] + ":");
                }
                if (i == 1) {
                    tv_dengdai1.setText(split[1]);
                }

            }
            if (time1 > 0) {
                handler2.postDelayed(this, 1000);
            }
        }
    };
    Runnable runnable2 = new Runnable() {
        @Override
        public void run() {
            time2--;
            String formatLongToTimeStr = formatLongToTimeStr(time2);
            String[] split = formatLongToTimeStr.split("：");
            for (int i = 0; i < split.length; i++) {
                if (i == 0) {
                    tv_dengdai.setText(split[0] + ":");
                }
                if (i == 1) {
                    tv_dengdai1.setText(split[1]);
                }

            }
            if (time2 > 0) {
                handler3.postDelayed(this, 1000);
            }
        }
    };
    Runnable runnable3 = new Runnable() {
        @Override
        public void run() {
            time3--;
            String formatLongToTimeStr = formatLongToTimeStr(time3);
            String[] split = formatLongToTimeStr.split("：");
            for (int i = 0; i < split.length; i++) {
                if (i == 0) {
                    tv_dengdai.setText(split[0] + ":");
                }
                if (i == 1) {
                    tv_dengdai1.setText(split[1]);
                }

            }
            if (time3 > 0) {
                handler4.postDelayed(this, 1000);
            }
        }
    };

    public String formatLongToTimeStr(Long l) {
        int minute = 0;
        int second = 0;
        second = l.intValue();
        if (second > 60) {
            minute = second / 60;         //取整
            second = second % 60;         //取余
        }

//        if (minute > 60) {
//            hour = minute / 60;
//            minute = minute % 60;
//        }
        String strtime = minute + "：" + second;
        return strtime;

    }

    //到达上车点
    private void arrivedParking(int state_cilcks) {

        UserNetWorks.arrivedParking(order_id, new Subscriber<ArrivedParking>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                sliderControlView.setVisibility(View.VISIBLE);
                ll_bottom1.setVisibility(View.GONE);
                JUtils.Toast("网络错误,请重新滑动滚动条");
                if (state_cilcks == 0) {
                    flag_stateclick = false;
                } else if (state_cilcks == 1) {
                    flag_stateclick1 = false;
                } else if (state_cilcks == 2) {
                    flag_stateclick2 = false;
                } else if (state_cilcks == 3) {
                    flag_stateclick3 = false;
                }

            }

            @Override
            public void onNext(ArrivedParking arrivedParking) {

                Log.e("111", arrivedParking.getReturn_code());
                if (arrivedParking.getReturn_code().equals("SUCCESS")) {
                    flag_stateclick = true;
                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);

                    SharedPreferences sp = JUtils.getSharedPreference();
                    SharedPreferences.Editor spEd = sp.edit();
                    if (state_cilcks == 0) {
                        order_state = "4";
                        Log.e("111", "currentTime");
                        spEd.putLong("currentTime", TimeUtil.getCurTimeLong1());
                        spEd.commit();
                        departure_time = adapterListData.get(0).getDeparture_time();
                        getTimeCha(departure_time);

                    } else if (state_cilcks == 1) {
                        order_state1 = "4";
                        Log.e("111", "currentTime1");
                        spEd.putLong("currentTime1", TimeUtil.getCurTimeLong1());
                        spEd.commit();
                        departure_time = adapterListData.get(1).getDeparture_time();
                        getTimeCha(departure_time);
                    } else if (state_cilcks == 2) {
                        order_state2 = "4";
                        Log.e("111", "currentTime2");
                        spEd.putLong("currentTime2", TimeUtil.getCurTimeLong1());
                        spEd.commit();
                        departure_time = adapterListData.get(2).getDeparture_time();
                        getTimeCha(departure_time);
                    } else if (state_cilcks == 3) {
                        order_state3 = "4";
                        Log.e("111", "currentTime3");
                        spEd.putLong("currentTime3", TimeUtil.getCurTimeLong1());
                        spEd.commit();
                        departure_time = adapterListData.get(3).getDeparture_time();
                        getTimeCha(departure_time);
                    }

                } else if (arrivedParking.getReturn_code().equals("FAIL")) {

                }
            }
        });


    }


    //立即出发
    private void departure(int state_cilckz) {

        UserNetWorks.departure(order_id, new Subscriber<Departure>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                rl_chufa.setEnabled(true);
                rl_chufa.setBackgroundColor(getResources().getColor(R.color.colorWhite));
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(Departure departure) {

                Log.e("111", departure.getReturn_code());
                if (departure.getReturn_code().equals("SUCCESS")) {
                    rl_chufa.setEnabled(true);
                    rl_chufa.setBackgroundColor(getResources().getColor(R.color.colorWhite));
                    rl_chufa.setVisibility(View.GONE);
                    rl_daoda.setVisibility(View.VISIBLE);
                    time = 1;
                    time1 = 1;
                    time2 = 1;
                    time3 = 1;
                    if (state_cilckz == 0) {
                        order_state = "5";
                    } else if (state_cilckz == 1) {
                        order_state1 = "5";
                    } else if (state_cilckz == 2) {
                        order_state2 = "5";
                    } else if (state_cilckz == 3) {
                        order_state3 = "5";
                    }

                } else if (departure.getReturn_code().equals("FAIL")) {

                }
            }
        });


    }


    //确认送达
    private void destination(int state_cilckx) {

        UserNetWorks.destination(order_id, new Subscriber<ArrivedDestination>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                rl_daoda.setEnabled(true);
                rl_daoda.setBackgroundColor(getResources().getColor(R.color.colorWhite));
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(ArrivedDestination destination) {

                Log.e("111", destination.getReturn_code());
                if (destination.getReturn_code().equals("SUCCESS")) {
                    rl_daoda.setEnabled(true);
                    rl_daoda.setBackgroundColor(getResources().getColor(R.color.colorWhite));

                    if (destination.getReturn_body().getIsCompleted().equals("NO")) {
                        rl_quanbu_s.setVisibility(View.VISIBLE);
                        rl_middle1.setVisibility(View.GONE);
                        rl_time_before.setVisibility(View.GONE);
                        ll_bottom1.setVisibility(View.GONE);
                        rl_chufa.setVisibility(View.GONE);
                        sliderControlView.setVisibility(View.GONE);

                        ll_jiesuan_next.setVisibility(View.VISIBLE);
                        tv_jiesuan.setText("全部学生送达之后可结算");
                        ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_hui));
                        ll_jiesuan_next.setEnabled(false);
                    } else if (destination.getReturn_body().getIsCompleted().equals("YES")) {
                        rl_quanbu_s.setVisibility(View.VISIBLE);
                        rl_middle1.setVisibility(View.GONE);
                        rl_time_before.setVisibility(View.GONE);
                        ll_bottom1.setVisibility(View.GONE);
                        sliderControlView.setVisibility(View.GONE);
                        iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        iv_lv_yuan2.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        iv_lv_yuan3.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);

                        ll_jiesuan_next.setVisibility(View.VISIBLE);
                        tv_jiesuan.setText(R.string.click_jiesuan);
                        ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_lan));
                        ll_jiesuan_next.setEnabled(true);

                        rl_touxiang.setBackgroundResource(R.drawable.xian_kuang_lv);
                        tv_touxiang.setTextColor(Color.parseColor("#2ebf12"));
                        rl_touxiang1.setBackgroundResource(R.drawable.xian_kuang);
                        tv_touxiang1.setTextColor(Color.parseColor("#8a8a8a"));
                        rl_touxiang2.setBackgroundResource(R.drawable.xian_kuang);
                        tv_touxiang2.setTextColor(Color.parseColor("#8a8a8a"));
                        rl_touxiang3.setBackgroundResource(R.drawable.xian_kuang);
                        tv_touxiang3.setTextColor(Color.parseColor("#8a8a8a"));

                    }
                    if (state_cilckx == 0) {
                        order_state = "6";
                        iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        tv_yisong.setText(adapterListData.get(0).getName() + "已送达");
                    } else if (state_cilckx == 1) {
                        order_state1 = "6";
                        iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        tv_yisong.setText(adapterListData.get(1).getName() + "已送达");
                    } else if (state_cilckx == 2) {
                        order_state2 = "6";
                        iv_lv_yuan2.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        tv_yisong.setText(adapterListData.get(2).getName() + "已送达");
                    } else if (state_cilckx == 3) {
                        order_state3 = "6";
                        iv_lv_yuan3.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
                        tv_yisong.setText(adapterListData.get(3).getName() + "已送达");
                    }

                } else if (destination.getReturn_code().equals("FAIL")) {

                }
            }
        });


    }


    private void stateall() {

        rl_quanbu_s.setVisibility(View.VISIBLE);
        rl_middle1.setVisibility(View.GONE);
        rl_time_before.setVisibility(View.GONE);
        ll_bottom1.setVisibility(View.GONE);
        sliderControlView.setVisibility(View.GONE);

        ll_jiesuan_next.setVisibility(View.VISIBLE);
        tv_jiesuan.setText(R.string.click_jiesuan);
        ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_lan));
        ll_jiesuan_next.setEnabled(true);
        iv_lv_yuan.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
        iv_lv_yuan1.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
        iv_lv_yuan2.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
        iv_lv_yuan3.setBackgroundResource(R.drawable.yuan_shixin_lv_kuang);
    }

    //状态改变方法
    private void stateWhere(String order_state, List<OrderDriver.ReturnBodyBean.StudentInfoBean> list, int position) {

        if (list.size() == 4) {
            if (order_state.equals("6") && order_state1.equals("6") && order_state2.equals("6") && order_state3.equals("6")) {
                stateall();

            } else {
                if (order_state.equals("3")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.VISIBLE);
                    ll_bottom1.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                } else if (order_state.equals("4")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                } else if (order_state.equals("5")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.GONE);
                    rl_daoda.setVisibility(View.VISIBLE);
                } else if (order_state.equals("6")) {
                    rl_quanbu_s.setVisibility(View.VISIBLE);
                    tv_yisong.setText(list.get(position).getName() + "已送达");
                    ll_jiesuan_next.setVisibility(View.VISIBLE);
                    tv_jiesuan.setText("全部学生送达之后可结算");
                    ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_hui));
                    ll_jiesuan_next.setEnabled(false);

                    rl_middle1.setVisibility(View.GONE);
                    rl_time_before.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.GONE);
                    sliderControlView.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.GONE);
                }

            }
        } else if (list.size() == 3) {
            if (order_state.equals("6") && order_state1.equals("6") && order_state2.equals("6")) {
                stateall();

            } else {
                if (order_state.equals("3")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.VISIBLE);
                    ll_bottom1.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                } else if (order_state.equals("4")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                } else if (order_state.equals("5")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.GONE);
                    rl_daoda.setVisibility(View.VISIBLE);
                } else if (order_state.equals("6")) {
                    rl_quanbu_s.setVisibility(View.VISIBLE);
                    tv_yisong.setText(list.get(position).getName() + "已送达");
                    ll_jiesuan_next.setVisibility(View.VISIBLE);
                    tv_jiesuan.setText("全部学生送达之后可结算");
                    ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_hui));
                    ll_jiesuan_next.setEnabled(false);

                    rl_middle1.setVisibility(View.GONE);
                    rl_time_before.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.GONE);
                    sliderControlView.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.GONE);
                }

            }
        } else if (list.size() == 2) {
            if (order_state.equals("6") && order_state1.equals("6")) {
                stateall();

            } else {
                if (order_state.equals("3")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.VISIBLE);
                    ll_bottom1.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                } else if (order_state.equals("4")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                } else if (order_state.equals("5")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.GONE);
                    rl_daoda.setVisibility(View.VISIBLE);
                } else if (order_state.equals("6")) {
                    rl_quanbu_s.setVisibility(View.VISIBLE);
                    tv_yisong.setText(list.get(position).getName() + "已送达");
                    ll_jiesuan_next.setVisibility(View.VISIBLE);
                    tv_jiesuan.setText("全部学生送达之后可结算");
                    ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_hui));
                    ll_jiesuan_next.setEnabled(false);

                    rl_middle1.setVisibility(View.GONE);
                    rl_time_before.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.GONE);
                    sliderControlView.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.GONE);
                }

            }
        } else if (list.size() == 1) {
            if (order_state.equals("6")) {
                stateall();

            } else {
                if (order_state.equals("3")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.VISIBLE);
                    ll_bottom1.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                } else if (order_state.equals("4")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.VISIBLE);
                    rl_daoda.setVisibility(View.GONE);

                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                } else if (order_state.equals("5")) {
                    rl_quanbu_s.setVisibility(View.GONE);
                    ll_jiesuan_next.setVisibility(View.GONE);
                    rl_middle1.setVisibility(View.VISIBLE);
                    rl_time_before.setVisibility(View.VISIBLE);
                    sliderControlView.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.VISIBLE);
                    rl_chufa.setVisibility(View.GONE);
                    rl_daoda.setVisibility(View.VISIBLE);
                } else if (order_state.equals("6")) {
                    rl_quanbu_s.setVisibility(View.VISIBLE);
                    tv_yisong.setText(list.get(position).getName() + "已送达");
                    ll_jiesuan_next.setVisibility(View.VISIBLE);
                    tv_jiesuan.setText("全部学生送达之后可结算");
                    ll_jiesuan_next.setBackground(getResources().getDrawable(R.drawable.bg_dialog_hui));
                    ll_jiesuan_next.setEnabled(false);

                    rl_middle1.setVisibility(View.GONE);
                    rl_time_before.setVisibility(View.GONE);
                    ll_bottom1.setVisibility(View.GONE);
                    sliderControlView.setVisibility(View.GONE);
                    rl_chufa.setVisibility(View.GONE);
                }

            }
        }

    }

    private void rlXianshi() {
        time = 1;
        time1 = 1;
        time2 = 1;
        time3 = 1;
//        if(order_state.equals("4")){
//            time = 1;
//        }
//        if(order_state1.equals("4")){
//            time1 = 1;
//        }
//        if(order_state2.equals("4")){
//            time2 = 1;
//        }
//        if(order_state3.equals("4")){
//            time3 = 1;
//        }
        handler0.postDelayed(new Runnable() {
            @Override
            public void run() {
                rl_touxiang.setEnabled(true);
                rl_touxiang1.setEnabled(true);
                rl_touxiang2.setEnabled(true);
                rl_touxiang3.setEnabled(true);
            }
        }, 500);
        tv_dengdai.setText("00:");
        tv_dengdai1.setText("00");
    }


    private void orderSettlement() {

        //346 需要替换成driver_order_id
        UserNetWorks.orderSettlement("346", new Subscriber<OrderSettlement>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                bottomDialog.dismiss();
                tv_ok.setEnabled(true);
                JUtils.Toast("网络错误");
            }

            @Override
            public void onNext(OrderSettlement orderSettlement) {

                if (orderSettlement.getReturn_code().equals("SUCCESS")) {

                    bottomDialog.dismiss();
                    tv_ok.setEnabled(true);
                    Intent intent = new Intent(DingdanKanActivity.this, DingdanJiesuanActivity.class);
                    intent.putExtra("order_tiaozhuan", "1");
                    intent.putExtra("congestionMoney", orderSettlement.getReturn_body().getCongestionMoney());
                    intent.putExtra("waitMoney", orderSettlement.getReturn_body().getWaitMoney());
                    intent.putExtra("kmMoney", orderSettlement.getReturn_body().getKmMoney());
                    intent.putExtra("totalMoney", orderSettlement.getReturn_body().getTotalMoney());
                    intent.putExtra("congestionTime", String.valueOf(orderSettlement.getReturn_body().getCongestionTime()));
                    intent.putExtra("waitTime", String.valueOf(orderSettlement.getReturn_body().getWaitTime()));
                    intent.putExtra("km", orderSettlement.getReturn_body().getKm());
                    startActivity(intent);
                    finish();

                } else if (orderSettlement.getReturn_code().equals("FAIL")) {
                    bottomDialog.dismiss();
                    ll_jiesuan_next.setEnabled(true);
                    JUtils.Toast(orderSettlement.getReturn_msg());
                }
            }
        });


    }


    public class MyReceiver extends BroadcastReceiver {


        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            String count = bundle.getString("count");
            TtsUtil.getInstance().startSpeaking(count + "");
        }
    }
//    @Override
//    public void onGlobalLayout() {
//        rl_all.getViewTreeObserver().removeOnGlobalLayoutListener(this);
//        animFromY = rl_all.getHeight() - ll_top.getHeight();
//        rl_all.setTranslationY(animFromY);
//        animator = AnimUtil.getTranDownYAnim(animFromY, 0);
//        animator.setTarget(rl_all);
//        animator.setInterpolator(new LinearOutSlowInInterpolator());
//        animator.addListener(new AnimatorListenerAdapter() {
//            @Override
//            public void onAnimationEnd(Animator animation) {
//                super.onAnimationEnd(animation);
//                animEnd = !animEnd;
//            }
//        });
//    }


}
